package com.fanhang.samples.springboot.data.mongodb.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fanhang.samples.springboot.data.mongodb.domain.City;
import com.fanhang.samples.springboot.data.mongodb.service.CityRepository;

@Controller
@RequestMapping("/city")
public class CityController {
	
	@Value("${server.port:8080}")
	private Integer port;
	
	@Autowired
	private CityRepository repository;
	
	@ResponseBody
	@RequestMapping("/get")
	public City get(@RequestParam(value="id") Integer id) {
		Assert.notNull(id);
		return repository.findOne(id);
	}
	
	@ResponseBody
	@RequestMapping("/test")
	public Integer test() {
		return port;
	}
	
}
